// pages/m_institution_index/index.js
var router = require('../../utils/router/index.js');
// 捐赠方和医疗机构信息填写界面
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 医院名称
   */
  bind_name_1_Input: function(e){
    // console.log("bindcardInput"+e.detail.value)
    this.setData({
      bind_name_1_Input: e.detail.value
    })
  },

  /**
   * 医院网址
   */
  bind_name_2_Input: function(e){
    // console.log("bindcardInput"+e.detail.value)
    this.setData({
      bind_name_2_Input: e.detail.value
    })
  },

  /**
   * 医院地址
   */
  bind_name_3_Input: function(e){
    // console.log("bindcardInput"+e.detail.value)
    this.setData({
      bind_name_3_Input: e.detail.value
    })
  },

  bind_name_4_Input: function(e){
    // console.log("bindcardInput"+e.detail.value)
    this.setData({
      bind_name_4_Input: e.detail.value
    })
  },

  bind_name_5_Input: function(e){
    // console.log("bindcardInput"+e.detail.value)
    this.setData({
      bind_name_5_Input: e.detail.value
    })
  },

  bind_name_6_Input: function(e){
    // console.log("bindcardInput"+e.detail.value)
    this.setData({
      bind_name_6_Input: e.detail.value
    })
  },
  
  bind_name_7_Input: function(e){
    // console.log("bindcardInput"+e.detail.value)
    this.setData({
      bind_name_7_Input: e.detail.value
    })
  },

  bind_name_8_Input: function(e){
    // console.log("bindcardInput"+e.detail.value)
    this.setData({
      bind_name_8_Input: e.detail.value
    })
  },
  
  /**
   * 设置医院联系人
   */
  bind_contact_info: function(){
    router.push({ 
      name: 'contact_info',
      data: {
        ads: ''
        } 
      })
  },
  
  /**
   * 保存医院信息
   */
  bind_save_hospital: function(){
    var that = this
    wx.showNavigationBarLoading();
    wx.showLoading({
      title: '加载中',
    })
    wx.cloud.callFunction({
      // 云函数名称
      name: 'hospital',
      // 传给云函数的参数
      data:{
        "action": "operation_hospital_info",
        "hospital_name": that.data.bind_name_1_Input,
        "hospital_url": that.data.bind_name_2_Input,
        "hospital_phone": that.data.bind_name_3_Input,
        "hospital_mobile": that.data.bind_name_4_Input,
        "hospital_address": that.data.bind_name_5_Input,
        "hospital_public": that.data.bind_name_6_Input,
        "hospital_logo": "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1580967755478&di=10e3adf1e013777eed58fb2526f48c46&imgtype=0&src=http%3A%2F%2Fa1.att.hudong.com%2F43%2F94%2F01300543313351143573943818212_s.jpg",
        "hospital_content": that.data.bind_name_7_Input,
        // "hospital_need": [
        //   {
        //     "goods_name":"医用防护口罩",
        //     "stock":1000,
        //     "daily_usage":500,
        //     "standard":"GB 19083-2010"
        //   },
        //   {
        //     "goods_name":"医用外科口罩",
        //     "stock":200,
        //     "daily_usage":800,
        //     "standard":"YY 0469-2010"
        //   }
        // ]
      }
      
    })
    .then(res => {
      console.log(res.result._id) // 3
      if(res.result.errMsg == "collection.add:ok"){
        router.push({ 
          name: 'mission_company',
          data: {
            "_id":res.result._id,
            "action": "operation_hospital_info",
            "hospital_name": that.data.bind_name_1_Input,
            "hospital_url": that.data.bind_name_2_Input,
            "hospital_phone": that.data.bind_name_3_Input,
            "hospital_mobile": that.data.bind_name_4_Input,
            "hospital_address": that.data.bind_name_5_Input,
            "hospital_public": that.data.bind_name_6_Input,
            "hospital_logo": "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1580967755478&di=10e3adf1e013777eed58fb2526f48c46&imgtype=0&src=http%3A%2F%2Fa1.att.hudong.com%2F43%2F94%2F01300543313351143573943818212_s.jpg",
            "hospital_content": that.data.bind_name_7_Input,
            // "hospital_need": [
            //   {
            //     "goods_name":"医用防护口罩",
            //     "stock":1000,
            //     "daily_usage":500,
            //     "standard":"GB 19083-2010"
            //   },
            //   {
            //     "goods_name":"医用外科口罩",
            //     "stock":200,
            //     "daily_usage":800,
            //     "standard":"YY 0469-2010"
            //   }
            // ]
          } 
          })
      }
    wx.hideNavigationBarLoading();
    wx.hideLoading()
    })
    .catch(console.error);
    // wx.hideNavigationBarLoading();
    // wx.hideLoading()
  }

})